'''
Created on 2010-3-2

@author: Administrator
'''
import sys
from jolly.datastructures.Object import Object
from jolly.Array import Array
from jolly.QueueAsLinkedList import QueueAsLinkedList

class Algorithms(object):
    '''
    Contains a bunch of algorithms.
    '''


    @staticmethod
    def breadthFirstTraversal(tree):
        '''
        Does a breadth-first traversal of a tree and prints the key
        '''
        queue = QueueAsLinkedList()
        
        if not tree.isEmpy:
            queue.enqueue(tree)
        
        while not queue.isEmpty:
            t = queue.dequeue()
            print t.key
            for i in xrange(t.degree):
                subTree = t.getSubtree(i)
                
                if not subTree.isEmpty:
                    queue.enqueue(subTree)
        